<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>退货管理-仓库管理系统</title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;top: 0px;">

    <!-- start sp-wrapper -->
    <link rel="stylesheet" href="/sb/stock.css"/>
    <fieldset class="layui-elem-field">
        <legend>按条件搜索</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane1" method="get" action="/tui/order_send_retun_list">
                <div class="layui-form-item">

                    <div class="layui-inline">
                        <input type="text" name="orderNum" placeholder="订单号" class="layui-input" th:value="${orderNum}">
                    </div>
   
                    <div class="layui-inline">
                        <input type="text" name="logisticsCode" placeholder="物流单号" class="layui-input" th:value="${logisticsCode}">
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="status" id="status">
                                <option value="-1">全部</option>
                                <option th:each="item:${T(com.b2c.entity.enums.erp.EnumOrderReturnStatus).values()}"
                                        th:text="${item.name}" th:value="${item.index}">未发货
                                </option>
                            </select>
                        </div>
                    </div>
                    
<!--                    <div class="layui-inline">-->
<!--                        <label class="layui-form-label">订单时间</label>-->
<!--                        <div class="layui-input-inline">-->
<!--                            <input type="text" class="layui-input" name="startTime" id="startTime"-->
<!--                                   placeholder="yyyy-MM-dd" autocomplete="off">-->
<!--                        </div>-->
<!--                        <div class="layui-input-inline">-->
<!--                            <input type="text" class="layui-input" name="endTime" id="endTime" placeholder="yyyy-MM-dd"-->
<!--                                   autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn">搜索</button>
                        <i>总共：&nbsp;[[${totalSize}]]&nbsp;条记录</i>
                    </div>
                    <div class="layui-inline">
                        <a class="layui-btn layui-btn-primary" href="javascript:;" id="generate_purchase_btn">退供应商（<span id="order-num">0</span>）</a>

                        <a id="text_model" href="javascript:;" class="layui-btn layui-btn-primary layui-btn-sm">文本模式</a>
                    </div>

                </div>
            </form>



        </div>
    </fieldset>
    <div class="sp-wrapper">
<!--        <h2 class="sp-title"><span>退货订单(<i th:text="${totalSize}" style="color: red"></i>)</span></h2>-->
<!--        <form action="/order_return/list" method="get">-->
<!--            <div class="sp-tool">-->
<!--            <span class="fl">-->
<!--                <b><input type="text" name="number"  th:value="${number}" placeholder="输入退货单号">-->
<!--                <input type="submit" value="查询">-->
<!--                </b>-->
<!--            </span>-->
<!--            </div>-->
<!--        </form>-->
        <div class="sp-table">
            <form method="post" action="/tui/generate_purchase_for_return_list" id="generate_purchase">
            <table>
                <thead>
                <tr>
                    <th><input id="allCheck" type="checkbox"/>ID</th>
                    <th>源订单号</th>
                 
                    <th>商品图片</th>
                    <th>商品名</th>
                    <th>规格</th>
                    <th>SKU编码</th>
                    <th>数量</th>
                    <th>售后类型</th>
                    <th>签收时间</th>
                    <th>签收单号</th>
                    <th width="200px">备注</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="sp-data">
                <tr th:each="item:${list}">
                    <td>
                        <input type="checkbox" name="ids" th:value="${item.id}" th:if="${item.status == 2 && item.isSettle ==0}" class="ids currCheck" />
                        <h th:text="${item.id}"></h>
                      
                    </td>
                    <td >
                        <b th:text="${item.orderSn}"></b><br />
                        <b th:if="${item.shopType == 4}" style="color: rgb(74, 11, 212);" > <img src="https://img.alicdn.com/tps/i3/T1OjaVFl4dXXa.JOZB-114-114.png" style="width: 20px;height:20px"/></b>
                        <b th:if="${item.shopType == 5}" style="color: rgb(74, 11, 212);" ><img src="https://mms-static.pddpic.com/express/favicon.ico" style="width: 20px;height:20px"/></b>
                        <b th:if="${item.shopType == 6}" style="color: rgb(74, 11, 212);" ><img src="https://lf1-fe.ecombdstatic.com/obj/eden-cn/upqphj/homepage/icon.svg" style="width: 20px;height:20px"/></b>
                        <b th:text="${item.shopName}"></b>
                    </td>

                    <td>
                        <img th:src="${item.goodsImg}" width="50px" height="50px" />
                    </td>
                    <td th:text="${item.goodsName}"></td>
                    <td th:text="${item.goodsSpec}"></td>
                    <td th:text="${item.goodsSpecNumber}"></td>
                    <td th:text="${item.quantity}"></td>
                    <td>
                        <b th:if="${item.returnType == 1}" class="content" th:attr="code=${item.logisticsCode},remark=${item.remark},g=${#strings.abbreviate(item.goodsName,10)}">退货</b>
                        <b th:if="${item.returnType == 2}" style="color:#de9494;" class="content" th:attr="code=${item.logisticsCode},remark=${item.remark},g=${#strings.abbreviate(item.goodsName,10)}">换货</b>
                        <b th:if="${item.returnType == 9}" style="color:#de9494;" class="content" th:attr="code=${item.logisticsCode},remark=${item.remark},g=${#strings.abbreviate(item.goodsName,10)}">订单拦截</b>
                    </td>
                    <td th:text="${item.receiveTime}"></td>
                    <td >
                        <b th:text="${item.logisticsCode}" ></b>
                    </td>
                    <td >
                        <b style="color: red;" th:text="${item.remark}" ></b>
                        <b th:attr="data-id=${item.getId()},remark=${item.remark}"  class="sellerRemark">
                                <i class="layui-icon layui-icon-log"></i>
                        </b>
                    </td>
                    <td>
                        <b th:text="${T(com.b2c.entity.enums.erp.EnumOrderReturnStatus).getName(item.status)}"></b><br />
                        <b style="color: red;" th:if="${item.isSettle == 1}">已结算</b>
                    </td>

                    <td>
   
                        <a class="view upd_express" th:attr="data-id=${item.getId()}" href="javascript:;" th:if="${item.status==T(com.b2c.entity.enums.erp.EnumOrderReturnStatus).WaitReceive.getIndex()}" >修改物流</a>&nbsp;
                        <!-- <a class="view confirmReceive2" target="_blank" th:if="${item.status==T(com.b2c.entity.enums.erp.EnumOrderReturnStatus).Received.getIndex() || item.status==T(com.b2c.entity.enums.erp.EnumOrderReturnStatus).WaitReceive.getIndex()}" th:href="@{/order_return/stock_info_list(id=${item.id})}" >确认收货</a> -->
<!--                        <a class="view confirmReceive" th:if="${item.status < T(com.b2c.entity.enums.erp.EnumOrderReturnStatus).Received.getIndex()}" th:attr="order-id=${item.id}" >确认收货</a>-->
                       <!-- <a class="view confirmReceive1" target="_blank" th:if="${item.status==T(com.b2c.entity.enums.erp.EnumOrderReturnStatus).Received.getIndex()}" th:href="@{/order_return/bad_stock_list(id=${item.id})}" >放入不良品仓</a> -->
                       <a class="view confirmStockIn" th:attr="data-id=${item.id}" th:if="${item.status==T(com.b2c.entity.enums.erp.EnumOrderReturnStatus).Received.getIndex()}" href="javascript:;" style="margin-right:5px;">入库</a>
                       
                       <a class="addBadStock" th:attr="data-id=${item.id},quantity=${item.quantity}" th:if="${item.status==T(com.b2c.entity.enums.erp.EnumOrderReturnStatus).Received.getIndex()}" href="javascript:;"  style="margin-right:5px;">计损</a>
                       <a class="backBuyer " th:attr="data-id=${item.id}" th:if="${item.status==T(com.b2c.entity.enums.erp.EnumOrderReturnStatus).Received.getIndex()}" href="javascript:;"  style="margin-right:5px;">退回</a>
                       <a class="huanhuo "th:attr="data-id=${item.id}" th:if="${item.status==T(com.b2c.entity.enums.erp.EnumOrderReturnStatus).Received.getIndex() && item.returnType == 2}" href="javascript:;"  style="margin-right:5px;">换货</a>
                       
                    </td>
                </tr>
                </tbody>
            </table>
            </form>
            <div class="pages">
                <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
            </div>
        </div>
    </div>
    <script type="text/template" id="send-goods">
        <div class="T-box">
            <p><span>快递公司</span><input type="text" name="company"/></p>
            <p><span>快递单号</span><input type="text" name="express_code"/></p>
        </div>
    </script>
    <script type="text/template" id="addgoods">
        <div class="T-box">
            <p><span>规格编码</span><input type="text" name="specNum"/></p>
            <p><span>数量</span><input type="text" name="num"/></p>
        </div>
    </script>

    <script type="text/javascript" src="/sb/jquery.min.js"></script>
    <script type="text/javascript" src="/sb/Tips.min.js"></script>
    <script type="text/javascript">
        $(function () {

            function getDateTime(timestamp) {
                var date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
                var Y = date.getFullYear();
                var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
                var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
                var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours());
                var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
                var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
                return Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s;
            }
        });
    </script>
    <!-- end sp-wrapper -->
    <script>
        layui.use(['laydate', 'layer','form'], function () {
            var laydate = layui.laydate;
            var layer = layui.layer;
            var form = layui.form;
            $("#status").val([[${status}]]);
            form.render('select'); //刷新select选择框渲染

            $(function () {
                $('#allCheck').on('change', function (e) {
                    var checked = $('#allCheck').prop('checked');
                    $('.currCheck').prop('checked', checked);
                    $('#order-num').text(getNum());
                    $('#order-num_').text(getNum());
                });

                $('.currCheck').on('change', function (e) {
                    var allChecked;
                    for (var i = 0; i < $('.currCheck').length; i++) {
                        var checked = $('.currCheck').eq(i).prop('checked');
                        if (!checked) {
                            $('#allCheck').prop('checked', false);
                            $('#order-num').text(getNum());
                            $('#order-num_').text(getNum());
                        return;
                        }
                    }
                    $('#allCheck').prop('checked', true);
                    $('#order-num').text(getNum());
                    $('#order-num_').text(getNum());
                });

                function getNum() {
                    var num = 0;
                    for (var i = 0; i < $('.currCheck').length; i++) {
                        var checked = $('.currCheck').eq(i).prop('checked');
                        if (checked) {
                            num++;
                        }
                    }
                    return num;
                }
                //备注
                $(".sellerRemark").click(function(){
                    var id = $(this).attr('data-id');
                    var remarkT = $(this).attr('remark');
                    var $this = $(this); 
                    var obj = $(this).siblings('b').eq(0);

                    layer.prompt({
                        formType: 2,
                        value: remarkT,
                        title: '请输入备注'
                    }, function(value, index, elem){
                        var data = {id:id, remark:value};
                        $.ajax({
                            url: "/ajax_tui/remark_ajax",
                            type: "POST",
                            dataType: "JSON",
                            contentType: 'application/json',
                            data:JSON.stringify(data),
                            success: function (res) {

                                if(res.code == 0){
                                    $this.attr("remark",value)
                                    $(obj).text(value);
                                    layer.close(index)
                                    layer.msg(res.msg);
                                    // location=location;
                                }else
                                    layer.alert(res.msg);
                            }
                        });


                    });
            });

            //退货入库
            $('.confirmStockIn').click(function(){
                    var stcokNum = "";
                    var id = $(this).attr('data-id');
                    // alert(kuaidi)
                    // layer.prompt(formType = 1, title = false, value = kuaidi);
                    layer.prompt({
                        formType: 3,
                        value: stcokNum,
                        title: '输入仓库编码入库'
                    }, function(value, index, elem){
                        var data = {
                                returnId: id,
                                stcokNum: value
                            };
                            $.ajax({
                                url: "/ajax_tui/return_stock_in",
                                type: "POST",
                                dataType: 'json',
                                contentType: 'application/json',
                                data: JSON.stringify(data),
                                success: function (res) {
                                    layer.close(index)
                                    layer.msg(res.msg);
                                    //window.location.reload();
                                }
                            });
                    });
                })


                //计损
                $('.addBadStock').click(function(){
                    var quantity = $(this).attr('quantity');
                    var id = $(this).attr('data-id');
                    // alert(kuaidi)
                    // layer.prompt(formType = 1, title = false, value = kuaidi);
                    layer.prompt({
                        formType: 3,
                        value: quantity,
                        title: '输入计损数量'
                    }, function(value, index, elem){
                        var data = {
                                returnId: id,
                                quantity: value
                            };
                            $.ajax({
                                url: "/ajax_tui/add_bad_stock",
                                type: "POST",
                                dataType: 'json',
                                contentType: 'application/json',
                                data: JSON.stringify(data),
                                success: function (res) {
                                    layer.close(index)
                                    layer.msg(res.msg);
                                    //window.location.reload();
                                }
                            });
                    });
                })

                //退回买家
                $('.backBuyer').click(function(){
                    var id = $(this).attr('data-id');
                    layer.msg("未实现")
                })
                //换货 
                $('.huanhuo').click(function(){
                    var id = $(this).attr('data-id');
                    layer.prompt({
                        formType: 3,
                        value: '',
                        title: '输入换货单号'
                    }, function(value, index, elem){
                        var data = {
                                returnId: id,
                                code: value
                            };
                            $.ajax({
                                url: "/ajax_tui/huanhuo_send",
                                type: "POST",
                                dataType: 'json',
                                contentType: 'application/json',
                                data: JSON.stringify(data),
                                success: function (res) {
                                    layer.close(index)
                                    layer.msg(res.msg);
                                    //window.location.reload();
                                }
                            });
                    });
                })

                //文本模式
                $("#text_model").click(function(){
                    var remarkT = "";
                    $(".content").each(function(){
                        var t = $(this).text();
                        var c = $(this).attr("code");
                        var g = $(this).attr("g");
                        var r = $(this).attr("remark");
                        if(r == undefined) r='';

                        remarkT += t+"："+c+"("+g+")"+r+"\r\n";
                    })
                    layer.prompt({
                    formType: 2,
                    value: remarkT,
                    title: '文本模式'
                    });
                })//文本模式结束

            });//jq fun end
        })

        
          
        

        // (按退货生成采购退货单)
        $("#generate_purchase_btn").click(function () {
                var ids = [];
                $("input[name^='ids']").each(function (i, el) {
                    if ($(this).is(':checked'))
                        ids.push($(this).val());
                });
                //console.log(ids);
                if (ids.length == 0)
                    alert("请选择订单");
                else {
                    if (confirm("你选中的订单将会生成采购单，确认要操作吗？")) {
                        $("#generate_purchase").submit();
                    }
                }
            });

        // 填写物流
        $('.upd_express').click(function (e) {
            e.stopPropagation();
            e.preventDefault();
            var id = $(this).attr('data-id');
            Tips.confirm({
                title: '修改退货物流',
                content: $('#send-goods').html(),
                define: function () {
                    var data = {
                        id: id,
                        company: $("input[name='company']").val(),
                        expressCode: $("input[name='express_code']").val()
                    };
                    // $.ajax({
                    //     url: "/ajax_order/upd_erp_order_return_code",
                    //     type: "POST",
                    //     dataType: 'json',
                    //     contentType: 'application/json',
                    //     data: JSON.stringify(data),
                    //     success: function (res) {
                    //         if (res.code == 0) {
                    //             Tips.alert('成功', function () {
                    //                 location.reload(true);
                    //             });
                    //         } else {
                    //             Tips.alert(res.msg);
                    //         }
                    //     }
                    // });
                }
            });
        });
        
    
    </script>
</div>
</body>
<html>
